/* 
 * Data Explorer: Error Elements
 *      errorElements.js
 *
 * last modified: 11/8/10
 * author: James Duran
 *
 * description: Provides the main control file
 *              with error handling related functions. For
 *              instance, functions that display modal dialogs
 *              with a purpose of displaying error information.
 *
 * comments: n/a
 */

function createErrorDiv(message) {
    showProgress(true, false,
                 "<p class='ui-state-error ui-corner-all' style='padding: 0pt 0.7em;'>" +
                 "<span class='ui-icon ui-icon-alert' style='float: left; margin-right: 0.3em;'>" +
                 "</span>" + message + "</p>");
}

// showErrorDialog
//
// display modal error dialog based on string title, message,
// and button array containing string button names and click event handlers
function showErrorDialog(title, message, button) {
    $("#errorDialog").empty().append("<p>" + message + "</p>");
    $("#errorDialog").dialog({autoOpen: false,
                              resizable: false,
                              modal: true,
                              buttons: button,
                              "title": title}).dialog("open");
}

// showTimeoutErrorDialog
//
// calls showErrorDialog to create a specific timeout error dialog
function showTimeoutErrorDialog() {
    showErrorDialog("Timeout Error",
                    "Ouch, unfortunately your data request has timed out." +
                    " What would you like to do?",
                    {"Abort this Request": function() {
                                      $(this).dialog("close");
                                      showProgress(true, false,
                                                   "<p class='ui-state-error ui-corner-all' style='padding: 0pt 0.7em;'>" +
                                                   "<span class='ui-icon ui-icon-alert' style='float: left; margin-right: 0.3em;'>" +
                                                   "</span>Your most recent data request has timed out." +
                                                   " Check your internet connection or try again later.</p>");
                                  }});
}

// showNoResultErrorDialog
//
// calls showErrorDialog to create a specific timeout error dialog
function showNoResultErrorDialog() {
    showErrorDialog("No Result Found",
		    "Hmm, Data Explorer was not able to find a relevant search result" +
		    " to your query. Please try rephrasing the query.",
		    {"Ok": function() {
			    $(this).dialog("close");
			}});
}

// showGeneralErrorDialog
//
// calls showGeneralErrorDialog to create a general purpose error dialog
function showGeneralErrorDialog() {
    showErrorDialog("Script Error",
                    "Yikes, something went wrong in processing your data" +
                    " request. An error must have occured within the script." +
                    " What would you like to do?",
                    {"Abort this Request": function() {
                                      $(this).dialog("close");
                                      showProgress(true, false,
                                                   "<p class='ui-state-error ui-corner-all' style='padding: 0pt 0.7em;'>" +
                                                   "<span class='ui-icon ui-icon-alert' style='float: left; margin-right: 0.3em;'>" +
                                                   "</span>An error has occured in processing your request." +
                                                   " You may want to try again later.</p>");
                                  }});
}
